package com.stronger.pettern.Single;

/**
 * 所谓饿汉，就是在类刚一初始化的时候就立即把单例对象创建出来
 * 优点：没有加锁，执行效率高
 * 缺点：当类加载时就初始化，没有懒加载，浪费内存。通过calssloader
 * 机制避免了多线程的同步问题
 */
public class HungrySingle {
//    private static Hungry instance=new Hungry();
//    private Hungry(){}
//    public static Hungry getInstance(){
//        return instance;
//    }
    private static HungrySingle instance=null;
    static {
        instance=new HungrySingle();
    }
    private HungrySingle(){}
    public static HungrySingle getInstance(){
        return instance;
    }

}
